package com.graphhopper.util.buffer;


import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.operation.buffer.BufferOp;

/**
 * 线型缓冲区域实现类
 * @author: heguanglong
 * @date: 2020-12-26
 **/
public class LineBufferImpl extends BufferBase implements BufferStrategy {
    @Override
    public String addBuffer(String gps, double rd) {
        Geometry gfLineString = geometryFactory.createLineString(getCoordinate(gps));
        Geometry buffer = getBuff(gfLineString, BufferOp.CAP_ROUND, rd);
        return gpsToString(buffer.getCoordinates());
    }

    @Override
    public String geometryInfo(String gps, double rd) {
        return  geometryFactory.createLineString(getCoordinate(gps)).toString();
    }

    @Override
    public Geometry geometry(String gps) {
        return geometryFactory.createLineString(getCoordinate(gps,","," "));
    }

    public Geometry geometry(Coordinate[] coordinates) {
        return geometryFactory.createLineString(coordinates);
    }

    public Polygon addBufferPolygon(String gps, double rd) {
        Geometry gfLineString = geometryFactory.createLineString(getCoordinate(gps));
        Geometry buffer = getBuff(gfLineString, BufferOp.CAP_ROUND, rd);
        return (Polygon) buffer;
    }
}
